//
//  HMNavigationViewController.swift
//  Weibo
//
//  Created by mac on 2017/6/5.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class HMNavigationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    //重写push
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count>0 {
            if viewControllers.count==1 {
                //获取第一季控制器
                let title = viewControllers.first!.title
                viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(title: title!,imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
                
            }else{
                viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(title: "返回",imageName:"navigationbar_back_withtext", target: self, action: #selector(backAction))
            }
             viewController.title = "当前显示的是第\(viewControllers.count + 1)级控制器"
        }
        super.pushViewController(viewController, animated: animated)
    }
    @objc private func backAction(){
        self.popViewController(animated: true)
    }
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        //  如果是根视图控制器，不需要开启边缘手势
        if viewControllers.count == 1 {
            return false
        }
        
        //  开启边缘手势
        return true
        
    }
    

}
